//
//  ST_AttributeLabelTool.m
//  ST_BaseMall
//
//  Created by 李宇廷 on 2022/9/10.
//

#import "ST_AttributeLabelTool.h"

@implementation ST_AttributeLabelTool

+ (NSAttributedString *)handleLabelWithContent:(NSString *)string SelectContent:(NSString *)selectString CommonFont:(UIFont *)comFont SpeFont:(UIFont *)speFont Color:(UIColor *)color {
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //设置省略
    paraStyle.lineBreakMode = NSLineBreakByTruncatingTail;
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:comFont, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.0f
                          };
    NSString *string1 = [NSString stringWithFormat:@"%@",string];
    NSString *selectStr = [NSString stringWithFormat:@"%@",selectString];
    NSMutableAttributedString *mutableStr = [[NSMutableAttributedString alloc]initWithString:string1 attributes:dic];
    NSRange range = [string1 rangeOfString:selectStr];
    //给某段字体设置颜色
    [mutableStr addAttribute:NSForegroundColorAttributeName value:color range:range];
    //给某段字体设置字号
    [mutableStr addAttribute:NSFontAttributeName value:speFont range:range];
    return mutableStr;
}

@end
